package com.fancon.android.gardenjokesx.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.fancon.android.gardenjokesx.entity.FavourisTagsNews;
import com.fancon.android.ui.widget.ImageCacheView;

public class FavoristTagNewAdapter extends BaseAdapter{

	Context mContext;
	ArrayList<FavourisTagsNews> mListTag;
	LayoutInflater inflater;
	public FavoristTagNewAdapter(Context context, ArrayList<FavourisTagsNews> listTag) {
		mContext = context;
		mListTag = listTag;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if(mListTag.size() <= 100){
			return mListTag.size();
		}else {
		return 100;
		}
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
//		ViewHolder holder = null;
//		View vi = convertView;
//		int type = mListTag.get(position).getType();
//		final FavourisTagsNews index = mListTag.get(position);
//		if(vi==null){
//			vi = inflater.inflate(R.layout.u22_common_item,null);
//			holder = new ViewHolder();
//			holder.txtMessage = (TextView) vi.findViewById(R.id.U22_common_txtMSG);
//			holder.txtTimePost = (TextView)vi.findViewById(R.id.U22_common_txtTime);
//			holder.imgAvatar = (ImageCacheView)vi.findViewById(R.id.U22_common_imgAvar);
//			holder.imgThumbnail = (ImageCacheView)vi.findViewById(R.id.U22_common_imgThumbnail);
//			vi.setTag(holder);
//		} else {
//			holder = (ViewHolder) vi.getTag();
//			
//		}
//		if(type == 1 || type == 2){
//			Drawable img = mContext.getResources().getDrawable( R.drawable.u21_vanguard_icon );
//			img.setBounds( 0, 0, 27, 27 );
//			ImageSpan span = new ImageSpan(img);
//			holder.imgAvatar.setVisibility(View.GONE);
//			holder.imgThumbnail.setVisibility(View.GONE);
//			holder.txtMessage.setText(mContext.getString(R.string.MSG_U0031,"#"+index.getTag_name(),index.getContent()));
//		}
//		if(type == 3){
//			holder.imgAvatar.setVisibility(View.GONE);
//			holder.imgThumbnail.setVisibility(View.VISIBLE);
//			holder.txtMessage.setText(mContext.getString(R.string.MSG_U0032,"#"+index.getTag_name()));
//			holder.imgThumbnail.loadImage(mListTag.get(position).getObject_url());
//			Log.d("photo id favor", index.getObject_id());
//			holder.imgThumbnail.setOnClickListener(new OnClickListener() {
//				
//				@Override
//				public void onClick(View v) {
//					Intent i = new Intent(mContext, M03_1Activity.class);
//					i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//					i.putExtra(Constant.PHOTO_ID, index.getObject_id());
//					mContext.startActivity(i);	
//				}
//			});
//		}
//		if(type == 4){
//			holder.imgAvatar.setVisibility(View.VISIBLE);
//			holder.imgAvatar.loadImage(mListTag.get(position).getObject_url());
//			holder.txtMessage.setText("");
//			holder.imgAvatar.setOnClickListener(new OnClickListener() {
//				
//				@Override
//				public void onClick(View v) {
//					Intent i = new Intent(mContext, M04Activity.class);
//					i.putExtra(Constant.USER_ID_VIEW, index.getObject_name());
//					i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//					mContext.startActivity(i);	
//				}
//			});
//			holder.imgThumbnail.setVisibility(View.GONE);
//			String text = mContext.getString(R.string.MSG_U0033,index.getObject_name(),"#"+index.getTag_name());
//			String userName = text.substring(0, index.getObject_name().length());
//			String str1 = text.substring(index.getObject_name().length(), text.indexOf("master")-1);
//			String str2 = text.substring(text.indexOf("master"), text.indexOf("#")-1);
//			String str3 = "#"+index.getTag_name();
//			Spannable WordtoSpan = new SpannableString(userName);      
//			WordtoSpan.setSpan(new StringUtil.NonUnderlinedClickableSpan(){
//				@Override
//				public void onClick(View widget) {
//					Intent i = new Intent(mContext, M04Activity.class);
//					i.putExtra(Constant.USER_ID_VIEW, index.getObject_name());
//					i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//					mContext.startActivity(i);
//				}
//			}, 0, index.getObject_name().toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//			holder.txtMessage.append(WordtoSpan);
//			holder.txtMessage.append(str1);
//			holder.txtMessage.append(Html.fromHtml("<img src=\"u21_master_icon.png\"/>", imgGetter, null));
//			holder.txtMessage.append(str2);
//			Spannable WordtoSpan2 = new SpannableString(str3);
//			WordtoSpan2.setSpan(new StringUtil.NonUnderlinedClickableSpan() {
//				
//				@Override
//				public void onClick(View widget) {
//					Log.d("main", "link clicked");
//					Intent i = new Intent(mContext, T02Activity.class);
//					i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//					i.putExtra(Constant.TAG_NAME, index.getTag_name());
//					i.putExtra(Constant.SCREEN_ID, Constant.U21);
//					mContext.startActivity(i);
//				}
//			}, 0, index.getTag_name().toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//			holder.txtMessage.append(WordtoSpan2);
//		}
//		if(type == 5){
//			holder.imgAvatar.setVisibility(View.GONE);
//			holder.imgThumbnail.setVisibility(View.GONE);
//			holder.txtMessage.setText(mContext.getString(R.string.MSG_U0034,"#"+index.getTag_name()));
//		}
//		if(type == 6){
//			holder.imgAvatar.setVisibility(View.GONE);
//			holder.imgThumbnail.setVisibility(View.GONE);
//			holder.txtMessage.setText(mContext.getString(R.string.MSG_U0035,"#"+index.getTag_name(),index.getContent()));
//		}
//		if(type == 1 || type == 2 || type == 3 || type == 5 || type == 6){
//		Spannable WordtoSpan = new SpannableString(holder.txtMessage.getText().toString());        
//		int startPos = holder.txtMessage.getText().toString().lastIndexOf('#');
//		WordtoSpan.setSpan(new StringUtil.NonUnderlinedClickableSpan() {
//			
//			@Override
//			public void onClick(View widget) {
//				Log.d("main", "link clicked");
//				Intent i = new Intent(mContext, T02Activity.class);
//				i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//				i.putExtra(Constant.TAG_NAME, index.getTag_name());
//				mContext.startActivity(i);
//			}
//		}, startPos, startPos+index.getTag_name().toString().length()+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
////		WordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), startPos, startPos+index.getTag_name().toString().length()+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//		holder.txtMessage.setText(WordtoSpan);
//		}
//		holder.txtTimePost.setText(TimeUtil.getTimeCount(mListTag.get(position).getTime(), mContext));
//		holder.txtMessage.setLinkTextColor(mContext.getResources().getColor(R.color.common_text_isclick));
//		holder.txtMessage.setMovementMethod(LinkMovementMethod.getInstance());
		return convertView;
	}
//	private ImageGetter imgGetter = new ImageGetter() {
//
//        public Drawable getDrawable(String source) {
//                Drawable drawable = null;
////                drawable = mContext.getResources().getDrawable(R.drawable.u21_master_icon);
////                drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
//                return drawable;
//        }
//    };
	static class ViewHolder{
		ImageCacheView imgAvatar;
		ImageCacheView imgThumbnail;
		TextView txtMessage;
		TextView txtTimePost;
	}
}
